use std::path::Path;

use thiserror::Error;

use bc_base::{BlockId, TransactionId};

pub use crate::block_and_index_storage::BlockAndIndexStorage;
pub use crate::inner_storage::DbHashMap;
// pub use crate::misc_item_storage::misc_item_cache::MiscItemCache;
pub use crate::misc_item_storage::MiscItemStorage;
pub use crate::transaction_and_index_storage::TransactionAndIndexStorage;
pub use crate::wallet_storage::WalletStorage;

#[derive(Error, Debug, PartialEq)]
pub enum BlockDataStorageError {
    #[error("DbError error: {0}")]
    DbError(#[from] bc_db::DBError),

    // block not found
    #[error("Block({0}) not found")]
    BlockNotFound(BlockId),

    // block index not found
    #[error("BlockIndex({0}) not found")]
    BlockIndexNotFound(BlockId),

    // transaction not found
    #[error("Transaction({0}) not found")]
    TransactionNotFound(TransactionId),

    // transaction index not found
    #[error("TransactionIndex({0}) not found")]
    TransactionIndexNotFound(TransactionId),
}

mod inner_storage;
mod inner_wallet_storage;

mod block_and_index_storage;
mod misc_item_storage;
mod transaction_and_index_storage;
mod wallet_storage;

pub fn get_wallet_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("wallet")
}

pub(crate) fn get_transactions_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("transactions")
}

pub(crate) fn get_transactions_index_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("transactions_index")
}

pub(crate) fn get_blocks_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("blocks")
}

pub(crate) fn get_blocks_index_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("blocks_index")
}

pub(crate) fn get_misc_item_db_path(db_dir: &Path) -> std::path::PathBuf {
    db_dir.join("misc_items")
}
